#ifndef _SVM_KERNEL_CLASSIFIER_H
#define _SVM_KERNEL_CLASSIFIER_H

#include "pn.h"
#include "svm.h"


#define Malloc(type,n) (type *)malloc((n)*sizeof(type))

class svm_kernel_classifier {
   bool trained;
   vector <int> pos, neg;
   vector <double> wp, wn; // weights of pos & neg examples

   int l;
   svm_parameter param;
   svm_model *model;
   svm_problem prob;

   double findKernelUn(int i, int j) const;
   double findKernel(int i, int j) const;


   public:

       svm_kernel_classifier() {
	  trained = false;
	  model= NULL;
       }
       
       /*
       svm_kernel_classifier (const svm_kernel_classifier &o) {
	  trained = o.trained;
	  model = NULL;
	  if (! trained) return;
	  l = o.l;
	  pos = o.pos;
	  neg = o.neg;
	  param = o.param;
	  model = svm_copy_model(o.model);
       }*/

       /*
       void operator=(const svm_kernel_classifier &o) {
	  trained = o.trained;
	  if (! trained) return;
	  l = o.l;
	  pos = o.pos;
	  neg = o.neg;
	  param = o.param;
	  model = svm_copy_model(o.model);
       }*/
       
      ~svm_kernel_classifier () {
	 if (trained) {
	    svm_destroy_model(model);
	    svm_destroy_param(&param);
	   /* free(prob.y);
	    for (int j=0; j<prob.l; ++j) {
	       free(prob.x[j]);
	    }
	    free(prob.x);
	    */
	 }
      }
      void train(const vector <int> &pos, const vector <int> &neg);
      void train_semi(const vector <int> &pos, const vector <int> &neg, const vector <int> &uneg);
      //double giveP(const vector <int> &st) const;
      double giveP(int i) const;
      double giveP(pn&tsw, int ind) const;      
      double giveDec(int i) const;
      double giveDec(pn &tsw, int i) const;
};

#endif
